﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>头像上传</title>
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/swfobject.js"></script>
    <script src="~/Scripts/fullAvatarEditor.js"></script>
    <script src="~/Resources/layer-3.0.1/layer.js"></script>
    <script src="~/Resources/tools/jquery-hcq2-extend.js"></script>
</head>
<body>
    <div style="width:632px;margin: 0 auto;text-align:center">
        <div>
            <p id="swfContainer">
                本组件需要安装Flash Player后才可使用，请从<a href="http://www.adobe.com/go/getflashplayer">这里</a>下载安装。
            </p>
        </div>
        <button type="button" id="upload" style="display:none;margin-top:8px;">swf外定义的上传按钮，点击可执行上传保存操作</button>
    </div>
    <script type="text/javascript">
        var $url = $.getUrls("url"), ishead = true, anyImg = $.getUrls("anyImg");
        var avatar_size = "200*200", avatar_size_desc = "200*200像素", widths = 630;
        if (anyImg) {
            widths = 1000;
            avatar_size = "500*300";//三组图片 表示一组或多组头像的尺寸。其间用"|"号分隔
            avatar_size_desc = "500*300像素";
            //avatar_size = "300*130|240*140|130*80";//三组图片 表示一组或多组头像的尺寸。其间用"|"号分隔
            //avatar_size_desc = "300*130像素 焦点新闻图片|240*140像素 新闻详细图片|130*80像素 新闻列表图片";
        } 
        if (!$url)
            $url = $.ctx() + '/Main/UploadImg';
        else{
            $url = $.ctx() + $url + "?user_identify=" + $.getUrls("user_identify");
            ishead=false;
        }
        swfobject.addDomLoadEvent(function () {
            var swf = new fullAvatarEditor("../Resources/headUpload/fullAvatarEditor.swf", "../Resources/headUpload/expressInstall.swf", "swfContainer", {
                id: 'swf',
                    height:500,
                    width: widths,
                    upload_url: $url,	//上传接口
					//upload_url: '../asp/Upload.ashx?userid=999&username=looselive',	//上传接口
					method : 'post',	//传递到上传接口中的查询参数的提交方式。更改该值时，请注意更改上传接口中的查询参数的接收方式
					src_upload: 0,		//是否上传原图片的选项，有以下值：0-不上传；1-上传；2-显示复选框由用户选择
					src_size: "2MB",//选择的本地图片文件所允许的最大值，必须带单位，如888Byte，88KB，8MB
					src_size_over_limit: "文件大小超出2MB，请重新选择图片。",//当选择的原图片文件的大小超出指定最大值时的提示文本。可使用占位符{0}表示选择的原图片文件的大小。
					avatar_box_border_width : 0,
					avatar_sizes: avatar_size,
					avatar_sizes_desc: avatar_size_desc
				}, function (msg) {
					switch(msg.code)
					{
						case 3 :
							if(msg.type === 0)
								layer.msg("摄像头已准备就绪且用户已允许使用。",{icon:6});
							else if(msg.type === 1)
								layer.msg("摄像头已准备就绪但用户未允许使用！",{icon:5});
							else
								layer.msg("摄像头被占用！",{icon:5});
						break;
						case 5 :
						    if (msg.type === 0 && !anyImg) {
						        //回调，修改头像
						        if (ishead)
									$('#ownHead', parent.document).attr("src",msg.content.avatarUrls.join("\n\n").replace("~",$.ctx())); 
						            //window.parent.mainManager.editHeadBack(msg.content.avatarUrls.join("\n\n").replace("~", $.ctx()));
						        else
						            parent.addBaneManager.editHeadBack(msg.content.avatarUrls.join("\n\n").replace("~", window.location.origin + $.ctx()));
						        //$('#ownHead', parent.document).attr("src",msg.content.avatarUrls.join("\n\n").replace("~",$.ctx())); 
						    } else {
						        //返回app上传图片路径
						        parent.newsManager.setImgUrl(msg.content.sourceUrl);
						    }
						break;
					}
				}
			);
			document.getElementById("upload").onclick=function(){
				swf.call("upload");
			};
        });
    </script>
</body>
</html>
